from typing import List

"""
# Definition for a Node.
class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children
"""


class Solution:
    def preorder(self, root: 'Node') -> List[int]:
        ans = []
        self.dfs(root, ans)
        return ans
    
    def dfs(self, node, ans):
        if node is None:
            return
        ans.append(node.val)
        if node.children is not None:
            for item in node.children:
              self.dfs(item, ans)
        return